package Touchy;


/**
 * The ScoreMeter is a JPanel used to illustrate the progress of resent scoring.
 * 
 * The meter is colored red, orange, yellow, and green, to show how well its player is doing, with red as bad, and green as good.
 * 
 * 
 * @author Sletten
 */


import java.awt.Color;
import java.awt.Graphics;


import javax.swing.JPanel;


@SuppressWarnings("serial")
public class ScoreMeter extends JPanel
{
        private int mScore; // The current score
        private int mPosScore; // Score to be added on a correct state
        private int mNegScore; // Score to be removed on a wrong state
        
        /**
         * Constructor.
         * Sets members to initial values
         */
        ScoreMeter()
        {
                mScore = 50;
                mPosScore = 2;
                mNegScore = 5;
        }
        
        /**
         * Constructor.
         * Makes it possible to set an initial score
         * 
         * @param inScore sets the initial score
         */
        ScoreMeter(int inScore)
        {
                mScore = inScore;
                mPosScore = 2;
                mNegScore = 5;
        }
        
        /**
         * @return the value of the positive scoring
         */
        public int getmPosScore()
        {
                return mPosScore;
        }
        /**
         * @param mPosScore sets the value of the positive score
         */
        public void setmPosScore(int mPosScore)
        {
                this.mPosScore = mPosScore;
        }
        /**
         * @return tje value of the negative score
         */
        public int getmNegScore()
        {
                return mNegScore;
        }
        /**
         * @param mNegScore sets the value of the negative score
         */
        public void setmNegScore(int mNegScore)
        {
                this.mNegScore = mNegScore;
        }
        /**
         * @param inScore is set to be the total score
         */
        public void setScore(int inScore)
        {
                mScore = inScore;
        }
        /**
         * @return total score
         */
        public int getScore()
        {
                return mScore;
        }
        /**
         * Adds the positive score to total score.
         */
        public void addScore()
        {
                mScore += mPosScore;
                if(mScore>100)
                        mScore = 100;
        }
        /**
         * Adds a defined positive score to the total score
         * @param inScore is addet to the total score
         */
        public void addScore(int inScore)
        {
                mScore += inScore;
                if(mScore>100)
                        mScore = 100;
        }
        /**
         * Subtracts the negative score from the total score
         */
        public void removeScore()
        {
                mScore -= mNegScore;
                if(mScore<= 0)
                    mScore = 0;
        }
        
        /**
         * Draws the meter in correct size and with colloring that matches the total score
         */
        public void paintComponent(Graphics g)
        {
                g.setColor(Color.BLACK);
                g.fillRect(0, 0, this.getWidth(), this.getHeight());
                
                if(mScore >= 70)
                {
                        g.setColor(Color.GREEN);
                }
                else if(mScore >= 40)
                {
                        g.setColor(Color.YELLOW);
                }
                else if(mScore > 20)
                {
                        g.setColor(Color.ORANGE);
                }
                else
                {
                        g.setColor(Color.RED);
                }
                
                g.fillRect(this.getWidth()*(100-mScore)/200, 0, (this.getWidth()*mScore/100), this.getHeight());
        }
}